//
//  MessageManager.m
//  tcpoctest
//
//  Created by gump on 1/7/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "MessageManager.h"
#import "XMMessageInfo.h"
#import "messagedb.h"
#import "MessageDataSource.h"


@implementation MessageManager

static MessageManager *sharedInstance = nil;

+(MessageManager*)sharedManager
{
    if(!sharedInstance)
    {
        sharedInstance = [[super alloc] init];
    }
    return sharedInstance;
}

-(void)AddMessage:(XMMessageInfo *)minfo
{
    [[DataControl shareControl].messageDS addMsg:minfo];
    [[DataBaseCtrol shareControl].messagedatabase insertMessage: minfo];
}

-(void)DeleteMessage:(XMMessageInfo *)minfo
{
    [[DataBaseCtrol shareControl].messagedatabase deleteMessage:minfo.strmail];
    [[DataControl shareControl].messageDS DelMsg:minfo];
}

-(XMMessageInfo *)getMessage:(XMMessageInfo *)minfo
{
    NSString *strid = [[DataBaseCtrol shareControl].messagedatabase getMessageID:minfo];
    
    if(![strid isEqualToString:@""])
    {
        XMMessageInfo *xmminfo = [[DataControl shareControl].messageDS getMsgInfoByID:strid];
        
       
        return xmminfo;
    }
    else
    {
        return nil;
    }
}
@end
